import event.EventBase;
import event.EventEnum;
import event.EventSystem;
import hud.UI;
import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Screen;
import javafx.stage.Stage;

public class Program extends Application {
    // forwarding ports
    private static final String LOCAL_HOST = "localhost";
    private static final String REMOTE_HOST = "127.0.0.1";
    private static final Integer LOCAL_PORT = 8988;
    private static final Integer REMOTE_PORT = 27017; // Default mongodb port

    // ssh connection info
    private static final String SSH_USER = "root";
    private static final String SSH_PASSWORD = "power*1122";
    private static final String SSH_HOST = "www.tianshubang.com";
    private static final Integer SSH_PORT = 22;

    public void start(Stage primaryStage) throws Exception {
        // create custom hud.UI
        UI ui = new UI();
        VBox viewBox = ui.init();

        Scene scene = new Scene(viewBox, 1024, 800);
        scene.widthProperty().addListener(ui);
        scene.getStylesheets().add("stylesheet.css");

        // this set stage to maximized
        Screen screen = Screen.getPrimary();
        Rectangle2D bounds = screen.getVisualBounds();
        primaryStage.setX(bounds.getMinX());
        primaryStage.setY(bounds.getMinY());
        primaryStage.setWidth(bounds.getWidth());
        primaryStage.setHeight(bounds.getHeight());

        // show all
        primaryStage.setTitle("EasyMongo");
        primaryStage.setScene(scene);
        primaryStage.setOnHiding(event -> {
            EventSystem.instance().dispatch(new EventBase(EventEnum.stageClose, null));
        });
        primaryStage.show();

        //
//        SshConnectionConfig config = new SshConnectionConfig();
//        config.setLocalHost(LOCAL_HOST);
//        config.setLocalPort(LOCAL_PORT);
//        config.setRemoteHost(REMOTE_HOST);
//        config.setRemotePort(REMOTE_PORT);
//        config.setSshHost(SSH_HOST);
//        config.setSshPassword(SSH_PASSWORD);
//        config.setSshPort(SSH_PORT);
//        config.setSshUser(SSH_USER);
//
//        SshConnection connection = new SshConnection(config);
//        DatabaseClient databaseClient = connection.connect();
//        MongoCursor<String> dbNames = databaseClient.getClient().listDatabaseNames().iterator();
//        while (dbNames.hasNext()) {
//            System.out.println(dbNames.next());
//        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}
